import sys
from PyQt6.QtWidgets import QApplication, QDialog, QVBoxLayout, QLabel, QPushButton, QDialogButtonBox, QWidget


class ConfirmDialog(QDialog):
    def __init__(self, title , text):
        super().__init__()
        self.setWindowTitle(title)

        layout = QVBoxLayout()

        self.message_label = QLabel(text, self)
        layout.addWidget(self.message_label)

        button_box = QDialogButtonBox(QDialogButtonBox.StandardButton.Ok)
        button_box.accepted.connect(self.accept)  # 点击Yes时接受对话框
        button_box.rejected.connect(self.reject)  # 点击No时拒绝对话框
        layout.addWidget(button_box)

        self.setLayout(layout)

    def get_result(self):
        return self.exec() == QDialog.DialogCode.Accepted  # 返回True表示用户点击了Yes


if __name__ == "__main__":
    app = QApplication(sys.argv)

    confirm_dialog = ConfirmDialog("title", "ok")
    result = confirm_dialog.get_result()

    if result:
        print("用户选择了继续")
    else:
        print("用户取消了操作")

    sys.exit(app.exec())
